package day0926_3;

import java.util.Iterator;
import java.util.TreeSet;

class  Teacher  implements   Comparable{
    double height;
    String name;
    public int compareTo(Object o) {//TeeSet集合会自动使用此方法对集合中的教师元素排序
        return   (int) (((Teacher)o).height  -this.height );
    }
}


public class T1 {
    public static void main(String[] args) {
        TreeSet<Teacher>  teachers=new TreeSet();//2.1
        //2.2.创建两个Teacher对象存入teachers集合
        Teacher   teacherH=new Teacher();   teacherH.height=210;
        Teacher   teacherZ=new Teacher();   teacherZ.height=173;
        teachers.add(teacherH);   teachers.add(teacherZ);
        Iterator<Teacher>  ite=teachers.iterator();//A.调用集合的iterator()
        while(ite.hasNext()){//B. ite的hasNext()
            Teacher  t=ite.next();//C.
            System.out.println(t.height);
        }
    }
}
